/*
  action:
    {
      type: xxx,
      payload: xxx
    }
*/
import { INCREMENT, DECREMENT } from "../action-types/counter";

interface ActionType {
  type: string;
  payload: any;
}

function counter(prevState = 0, action: ActionType) {
  switch (action.type) {
    case INCREMENT:
      return prevState + action.payload;
    case DECREMENT:
      return prevState - action.payload;
    default:
      return prevState;
  }
}

export default counter;
